<?php


namespace App\Model;


/**
 * App\Model\RulesGroup
 *
 * @property int $id
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property string $title 分组名称
 * @property string $rules 规则，多个以逗号分隔
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\RulesGroup newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\RulesGroup newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\RulesGroup query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\RulesGroup whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\RulesGroup whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\RulesGroup whereRules($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\RulesGroup whereTitle($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\RulesGroup whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class RulesGroup extends Base
{

    protected $table='rules_group';


    protected $fillable=['title','rules'];


    function setRulesAttribute($value){

        if(!$value) $this->attributes['rules']='';

        $this->attributes['rules']=join(',',$value);
    }


    function getRulesAttribute($value){

        if(!$value) return [];

        $list=explode(',',$value);

        $temp=[];

        foreach ($list as $key=>$value){

            $temp[]=(int)$value;

        }

        return $temp;

    }

}
